package com.yodawnla.littleWar.player;

import com.yodawnla.littleWar.card.HeroCard;
import com.yodawnla.littleWar.card.HandCard;
import com.yodawnla.littleWar.system.Values;

public class CmdHandler
{
	HeroCard mPlayerHero;
	HeroCard mEnemyHero;
	
	static CmdHandler instance = null;
	
	public static CmdHandler getInstance()
	{
		if (instance == null)
			instance = new CmdHandler();
		return instance;
	}
	
	public CmdHandler()
	{
	}
	
	public void initHero()
	{
		mPlayerHero = Player.getInstance().getDeck().getHeroCard();
		mEnemyHero = Npc.getInstance().getDeck().getHeroCard();
	}
	
	public int useCard(HandCard playerCard, HandCard enemyCard)
	{
		if(playerCard == null || enemyCard == null)
			return -1;
		
		switch(playerCard.getType())
		{
		case Values.HandCardType.Red:
			switch(enemyCard.getType())
			{
			case Values.HandCardType.Red:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Draw;
			case Values.HandCardType.Green:
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Win;
			case Values.HandCardType.Blue:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				return Values.Result.Lose;
			}
			break;
		case Values.HandCardType.Green:
			switch(enemyCard.getType())
			{
			case Values.HandCardType.Red:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				return Values.Result.Lose;
			case Values.HandCardType.Green:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Draw;
			case Values.HandCardType.Blue:
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Win;
			}
			break;
		case Values.HandCardType.Blue:
			switch(enemyCard.getType())
			{
			case Values.HandCardType.Red:
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Win;
			case Values.HandCardType.Green:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				return Values.Result.Lose;
			case Values.HandCardType.Blue:
				mPlayerHero.modifyHp(enemyCard.getDamage() - mEnemyHero.getAtk());
				mEnemyHero.modifyHp(playerCard.getDamage() - mPlayerHero.getAtk());
				return Values.Result.Draw;
			}
			break;
		}
		
		return -1;
	}
}